package com.bitcat.wanandroidapp.demo

import android.os.Bundle
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.lifecycleScope
import com.bitcat.base.core.BaseActivity
import com.bitcat.base.widget.EmptyCallback
import com.bitcat.base.widget.ErrorCallback
import com.bitcat.base.widget.LoadingCallback
import com.bitcat.wanandroidapp.MainViewModel
import com.bitcat.wanandroidapp.R
import com.bitcat.wanandroidapp.databinding.ActivityTestLoadsirBinding
import com.kingja.loadsir.callback.Callback
import com.kingja.loadsir.core.LoadService
import com.kingja.loadsir.core.LoadSir
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class TestLoadSirActivity : BaseActivity<MainViewModel, ActivityTestLoadsirBinding>() {


    lateinit var loadService: LoadService<*>

    override fun initView() {

        loadService = LoadSir.getDefault().register(binding.container,object : Callback.OnReloadListener{
            override fun onReload(v: View?) {
                //重新加载
                lifecycleScope.launch {
                    loadService.showCallback(LoadingCallback::class.java)  //显示加载中
                    delay(2000) //模拟加载
                    loadService.showSuccess() //显示成功
                }
            }
        })
    }

    fun clickLoading(view: View) {
        lifecycleScope.launch {
            loadService.showCallback(LoadingCallback::class.java)  //显示加载中
            delay(2000) //模拟加载
            loadService.showSuccess() //显示成功
        }
    }
    fun clickEmpty(view: View) {
        lifecycleScope.launch {
            loadService.showCallback(LoadingCallback::class.java)  //显示加载中
            delay(2000)
            loadService.showCallback(EmptyCallback::class.java)   //显示空
        }
    }
    fun clickError(view: View) {
        lifecycleScope.launch {
            loadService.showCallback(LoadingCallback::class.java)  //显示加载中
            delay(2000)
            loadService.showCallback(ErrorCallback::class.java)   // 显示错误
        }
    }

}